Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#14 [feat] Spring Rest Controller Advice 구현 #16

Merged
merged 14 commits into from
Jul 3, 2023

Conversation

2zerozu
Copy link
Collaborator

@2zerozu 2zerozu commented Jun 28, 2023

✒️ 관련 이슈번호

🔑 Key Changes

  1. ApiException과 관련 서브클래스 구현
  2. ControllerExceptionAdvice 구현

📢 To Reviewers

  • success 시에 데이터만 내려주므로 컨트롤러에서 직접 ResponseEntity를 반환하는 방식으로 가져가면 될 것 같습니다.
  • 에러 시에 response로 uniCode를 내려주도록 설정해줬습니다
  • ErrorType에 ""로 둔 곳에 uniCode를 넣으면 됩니다. 아직 정해진 바가 없어서 ""로 채워넣어놨습니다.
  • MissingRequestHeaderException는 ResponseEntityExceptionHandler의 메소드에 없어서 ExceptionHandler를 활용해 따로 만들었습니다.

@2zerozu 2zerozu added feat 새로운 기능 추가 pull request🔥 Good for newcomers 영주🐼 영주가 작업함! labels Jun 28, 2023
@2zerozu 2zerozu requested a review from a team as a code owner June 28, 2023 11:36
@2zerozu 2zerozu self-assigned this Jun 28, 2023
@2zerozu 2zerozu requested review from jinsu4755 and jiyeoon00 and removed request for a team June 28, 2023 11:36
Copy link
Member

@jinsu4755 jinsu4755 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~

기본적으로 body에 불필요한 정보인 http status code 가 들어가는 것을 막고자 success 에 body에 status code 를 제외하는 방식을 사용했는데 해당 경우에 결국 다시 body에 status code가 들어가는 것 같아요... 어떻게 해결하면 좋을지 논의 해보면 좋을 것 같습니다!

또한 패키징 관련이긴한데 개인적으로 controllerExceptionAdvice는 common 이라는 공통의 페키징에서 필요하기보다 발생한 에러를 처리하는 느낌이라 패키징을 모듈로서 나눈다면 controller 에서 이를 처리하는 것이 좋지 않을까? 생각이 듭니다!

또한 dto 패키징 또한 외부에서 따로 관리하기로 하였기 때문에 이 부분이 common 내부에 들어있을 필요는 없을 것 같아요 :)

dto 패키징 정도는 수정하면 좋을 것 같아서 해당 부분 수정되면 바로 approve 하겠습니다!

Copy link
Member

@jinsu4755 jinsu4755 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어프로브 눌러서 다시...ㅎㅎ

Copy link
Member

@jiyeoon00 jiyeoon00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넘 수고하셨습니다~~👍🏻

protected ErrorResponse handleException(final Exception exception) {
return ErrorResponse.error(ErrorType.INTERNAL_SERVER_ERROR);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MissingRequestHeaderException도 잡아서 request header가 없을 때 처리해주면 좋을 것 같아요!

public UnauthorizedException(ErrorType error) {
super(error, error.getMessage());
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BadRequestException, ConflictException, NotFoundException, UnauthorizedException 모두 ErrorType을 매개변수로 받아 ApiException에 넘겨주는 똑같은 역할을 하는데, 나눠서 커스텀 예외를 생성하신 이유가 궁금합니다...!

좀 더 명시적으로 어떤 관련 에러인지 보여주기 위함일까요...?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네!

  1. 예외 클래스 이름을 통해 예외의 원인을 빠르게 인지하여 가독성을 높임
  2. ApiException을 통해 구체적인 예외를 처리하기 위해서는 에러 메시지나 에러 타입을 체크하는 추가적인 로직이 필요함 (번거로움)

의 이유로 따로 나눴습니다

@2zerozu
Copy link
Collaborator Author

2zerozu commented Jul 1, 2023

고생하셨습니다~

기본적으로 body에 불필요한 정보인 http status code 가 들어가는 것을 막고자 success 에 body에 status code 를 제외하는 방식을 사용했는데 해당 경우에 결국 다시 body에 status code가 들어가는 것 같아요... 어떻게 해결하면 좋을지 논의 해보면 좋을 것 같습니다!

또한 패키징 관련이긴한데 개인적으로 controllerExceptionAdvice는 common 이라는 공통의 페키징에서 필요하기보다 발생한 에러를 처리하는 느낌이라 패키징을 모듈로서 나눈다면 controller 에서 이를 처리하는 것이 좋지 않을까? 생각이 듭니다!

또한 dto 패키징 또한 외부에서 따로 관리하기로 하였기 때문에 이 부분이 common 내부에 들어있을 필요는 없을 것 같아요 :)

dto 패키징 정도는 수정하면 좋을 것 같아서 해당 부분 수정되면 바로 approve 하겠습니다!

common.exception에 각각의 Exception 클래스들이, common.response controllerExceptionAdviceErrorResponse, ErrorType이 있는 건 어떤가요?
controllerExceptionAdvice가 전역에서 예외 핸들링 해주기 때문에..?, exception은 공통으로 관리해주기 때문에 common에 있어야한다고 생각했습니다!

@2zerozu 2zerozu merged commit 87e3ab3 into develop Jul 3, 2023
@2zerozu 2zerozu deleted the feature/#14-feat-rest-controller-advice branch July 3, 2023 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat 새로운 기능 추가 pull request🔥 Good for newcomers size/L 영주🐼 영주가 작업함!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat] Spring Rest Contoller Advice 설정
3 participants